﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

using MicroMq.Helper;
using MicroMq.Models;

namespace MicroMq.Services
{
    class DispatchService : IHandlerService
    {
        private readonly DispatchWorkService dispatchWorkService;

        public DispatchService(DispatchWorkService dispatchWorkService)
        {
            this.dispatchWorkService = dispatchWorkService;
        }

        byte IHandlerService.HandleType => (byte)HandleType.Dispatch;

        public void Hanlder(PeerConnection connection, ByteReadBuffer readBuffer)
        {
            string taskName = readBuffer.ReadUnknownString();
            string cronExpression = readBuffer.ReadUnknownString();
            connection.AddGroup(taskName, "default");
            dispatchWorkService.Enqueue(taskName, cronExpression);
        }
    }
}
